<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="../0505/js/jq.js"></script>
    <style>
        .item1 {
            float: left;
        }
    </style>
</head>

<body>
    <div class="page"></div>
    <!-- <div class="content">
        <p>shenghuo</p>
        <div class="item1">
            <img src="./img/cat_1.png" alt="">
            <p>sfawf(12)</p>
        </div>
        <div class="item1">
            <img src="./img/cat_1.png" alt="">
            <p>sfawf(12)</p>
        </div>
        <div class="item1">
            <img src="./img/cat_1.png" alt="">
            <p>sfawf(12)</p>
        </div>
    </div> -->
    <script>
        $(function () {

            window.onload = function () {
                // 自动加载数据
                getData()
            }

            var str1 = '';
            var strTotal = '';
            function getData() {
                $.ajax({
                    url: 'http://localhost:3000/play/category',
                    type: 'get',
                    success: function (res) {


                        // 开始循环
                        for (var x = 0; x < res.length; x++) {
                            // 添加标题
                            str1 = "<div class='content'>" +
                                "<p>" + res[x].title + "</p>";
                            $.each(res[x].list, function (i, item) {
                                if (i <= 10) {
                                    str1 += "<div class='item1'>" +
                                        "<img src=./img/cat_" + (i + 1) + ".png alt=>" +
                                        "<p>" + item.productName + "(" + item.nums + ")" + "</p>" +
                                        "</div>"
                                } else {
                                    str1 += "<div class='item1'>" +
                                        "<p>" + item.productName + "(" + item.nums + ")" + "</p>" +
                                        "</div>"
                                }
                            })
                            strTotal += str1
                        }
                        str1 += "</div>"




                        $('.page').html(strTotal)
                    }
                })
            }

        })
    </script>
</body>

</html>